
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

> rm(list=ls())
> gc()
         used (Mb) gc trigger (Mb) max used (Mb)
Ncells 217457 11.7     460000 24.6   350000 18.7
Vcells 319045  2.5     786432  6.0   786432  6.0
> require(foreign)
Loading required package: foreign
> require(ineq)
Loading required package: ineq
Warning message:
package 'ineq' was built under R version 3.3.2 
> require(dplyr)
Loading required package: dplyr

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

> library(Hmisc)
Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

The following objects are masked from 'package:dplyr':

    combine, src, summarize

The following objects are masked from 'package:base':

    format.pval, round.POSIXt, trunc.POSIXt, units

> require(corrplot)
Loading required package: corrplot
> require(systemfit)
Loading required package: systemfit
Loading required package: Matrix
Loading required package: car
Loading required package: lmtest
Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

> require(cem)
Loading required package: cem
Loading required package: tcltk

How to use CEM? Type vignette("cem")

> require(BayesTree)
Loading required package: BayesTree
> require(stargazer)
Loading required package: stargazer

Please cite as: 

 Hlavac, Marek (2015). stargazer: Well-Formatted Regression and Summary Statistics Tables.
 R package version 5.2. http://CRAN.R-project.org/package=stargazer 

> require(texreg)
Loading required package: texreg
Version:  1.36.23
Date:     2017-03-03
Author:   Philip Leifeld (University of Glasgow)

Please cite the JSS article in your publications -- see citation("texreg").
Warning message:
package 'texreg' was built under R version 3.3.3 
> require(igraph)
Loading required package: igraph

Attaching package: 'igraph'

The following objects are masked from 'package:dplyr':

    %>%, as_data_frame, groups, union

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union

> require(plotrix)
Loading required package: plotrix
> 
> setwd(paste(substr(getwd(),1,regexpr("Dropbox",getwd())[1]-1),"Dropbox/coauthors/AMT_Bisbee_Larson/bisbee_larson_replication_final",sep=""))
> source("./tools/leg2.R")
> 
> ###################################################################################
> ##
> ##  File Name:    chars_results.R
> ##
> ##  Input Files:  chars_data.dta
> ##                chars_diff.dta
> ##                data_prepped.dta
> ##  Output Files: chars_regs.tex                  (Table 3)
> ##                SI_chars_regs.pdf               (SI Figure 1)
> ##                chars_adjpvals.pdf              (Figure 4)
> ##                structure-diff-elicited.pdf     (Figure 6)
> ##                structure-diff-allchars.pdf     (Figure 7)
> ##
> ##  Purpose: This file conducts free-step down resampling to adjust statistical 
> ##            inference for multiple comparisons and generate Figures 4 and SI 
> ##            Figure 1. In addition, this file creates Table 3 and uses the dinner
> ##            table seating question to explore structure differences in Figures 6
> ##            and 7. Note that the chars_adjpvals.pdf (Figure 4) may differ slightly 
> ##            in appearance from the figure in the published paper. This is due to 
> ##            the randomness associated with the jittered points which are included
> ##            for visual clarity. The substantive conclusions should obtain despite 
> ##            these small differences. 
> ##
> ##############################################################################################
> 
> specify_decimal <- function(x, k) format(round(x, k), nsmall=k)
> startup <- function(x, out=NULL, ...){
+   undo <- gsub("\\\\textasteriskcentered", "*", stargazer(x))#, ...))
+   restar <- gsub("* * *", "${}^{***}$", undo, fixed = TRUE)
+   restar <- gsub("* *", "${}^{**}$", restar, fixed = TRUE)
+   restar <- gsub("* ", "${}^{*}$", restar, fixed = TRUE)
+   restar <- gsub("\\textbackslash","\\",restar,fixed = TRUE)
+   restar <- gsub("\\ textit\\{","\\textit{",restar,fixed = TRUE)
+   restar <- gsub("\\}","}",restar,fixed = TRUE)
+   if(!is.null(out)) cat(restar, file = out, sep="\n")
+   restar
+ }
> 
> getwd()
[1] "D:/Dropbox/coauthors/AMT_Bisbee_Larson/bisbee_larson_replication_final"
> 
> ######################################################################################
> # chars_regs.tex: Table 3
> ######################################################################################
> dat <- read.dta("./characteristics/chars_data.dta")
> dat <- dat %>% filter(complete.cases(.)) %>% select(-contains("donate")) %>% mutate(std_interaction_clique = std_interaction_clique *-1,std_interaction_weakest = std_interaction_weakest * -1,std_interaction_weak = std_interaction_weak * -1,std_interaction_strong = std_interaction_strong *-1,std_interaction_strongest = std_interaction_strongest*-1)
> # Prep work
> controls <- names(dat[,which(grepl("^dem_",colnames(dat)))])
> todrop <- c(names(dat[,which(grepl("^std_",colnames(dat)))]),
+             names(dat[,which(grepl("^dem_",colnames(dat)))]),
+             names(dat[,which(grepl("^tie_",colnames(dat)))]))
> cem.dat <- cem(treatment = "online",data=dat,drop=todrop)
> trees <- bart(x.train = dat %>% select(which(colnames(dat) %in% names(dat[,which(grepl("^dem_",colnames(dat)))]))),y.train = dat$online,ndpost=1000)
NOTE: assumming numeric response is binary


Running BART with binary y

number of trees: 200
Prior:
	k: 2.000000
	binary offset is: 0.000000
	power and base for tree prior: 2.000000 0.950000
	use quantiles for rule cut points: 0
data:
	number of training observations: 431
	number of test observations: 0
	number of explanatory variables: 274


Cutoff rules c in x<=c vs x>c
Number of cutoffs: (var: number of possible c):
(1: 100) (2: 100) (3: 100) (4: 100) (5: 100) 
(6: 100) (7: 100) (8: 100) (9: 100) (10: 100) 
(11: 100) (12: 100) (13: 100) (14: 100) (15: 100) 
(16: 100) (17: 100) (18: 100) (19: 100) (20: 100) 
(21: 100) (22: 100) (23: 100) (24: 100) (25: 100) 
(26: 100) (27: 100) (28: 100) (29: 100) (30: 100) 
(31: 100) (32: 100) (33: 100) (34: 100) (35: 100) 
(36: 100) (37: 100) (38: 100) (39: 100) (40: 100) 
(41: 100) (42: 100) (43: 100) (44: 100) (45: 100) 
(46: 100) (47: 100) (48: 100) (49: 100) (50: 100) 
(51: 100) (52: 100) (53: 100) (54: 100) (55: 100) 
(56: 100) (57: 100) (58: 100) (59: 100) (60: 100) 
(61: 100) (62: 100) (63: 100) (64: 100) (65: 100) 
(66: 100) (67: 100) (68: 100) (69: 100) (70: 100) 
(71: 100) (72: 100) (73: 100) (74: 100) (75: 100) 
(76: 100) (77: 100) (78: 100) (79: 100) (80: 100) 
(81: 100) (82: 100) (83: 100) (84: 100) (85: 100) 
(86: 100) (87: 100) (88: 100) (89: 100) (90: 100) 
(91: 100) (92: 100) (93: 100) (94: 100) (95: 100) 
(96: 100) (97: 100) (98: 100) (99: 100) (100: 100) 
(101: 100) (102: 100) (103: 100) (104: 100) (105: 100) 
(106: 100) (107: 100) (108: 100) (109: 100) (110: 100) 
(111: 100) (112: 100) (113: 100) (114: 100) (115: 100) 
(116: 100) (117: 100) (118: 100) (119: 100) (120: 100) 
(121: 100) (122: 100) (123: 100) (124: 100) (125: 100) 
(126: 100) (127: 100) (128: 100) (129: 100) (130: 100) 
(131: 100) (132: 100) (133: 100) (134: 100) (135: 100) 
(136: 100) (137: 100) (138: 100) (139: 100) (140: 100) 
(141: 100) (142: 100) (143: 100) (144: 100) (145: 100) 
(146: 100) (147: 100) (148: 100) (149: 100) (150: 100) 
(151: 100) (152: 100) (153: 100) (154: 100) (155: 100) 
(156: 100) (157: 100) (158: 100) (159: 100) (160: 100) 
(161: 100) (162: 100) (163: 100) (164: 100) (165: 100) 
(166: 100) (167: 100) (168: 100) (169: 100) (170: 100) 
(171: 100) (172: 100) (173: 100) (174: 100) (175: 100) 
(176: 100) (177: 100) (178: 100) (179: 100) (180: 100) 
(181: 100) (182: 100) (183: 100) (184: 100) (185: 100) 
(186: 100) (187: 100) (188: 100) (189: 100) (190: 100) 
(191: 100) (192: 100) (193: 100) (194: 100) (195: 100) 
(196: 100) (197: 100) (198: 100) (199: 100) (200: 100) 
(201: 100) (202: 100) (203: 100) (204: 100) (205: 100) 
(206: 100) (207: 100) (208: 100) (209: 100) (210: 100) 
(211: 100) (212: 100) (213: 100) (214: 100) (215: 100) 
(216: 100) (217: 100) (218: 100) (219: 100) (220: 100) 
(221: 100) (222: 100) (223: 100) (224: 100) (225: 100) 
(226: 100) (227: 100) (228: 100) (229: 100) (230: 100) 
(231: 100) (232: 100) (233: 100) (234: 100) (235: 100) 
(236: 100) (237: 100) (238: 100) (239: 100) (240: 100) 
(241: 100) (242: 100) (243: 100) (244: 100) (245: 100) 
(246: 100) (247: 100) (248: 100) (249: 100) (250: 100) 
(251: 100) (252: 100) (253: 100) (254: 100) (255: 100) 
(256: 100) (257: 100) (258: 100) (259: 100) (260: 100) 
(261: 100) (262: 100) (263: 100) (264: 100) (265: 100) 
(266: 100) (267: 100) (268: 100) (269: 100) (270: 100) 
(271: 100) (272: 100) (273: 100) (274: 100) 


Running mcmc loop:
iteration: 100 (of 1100)
iteration: 200 (of 1100)
iteration: 300 (of 1100)
iteration: 400 (of 1100)
iteration: 500 (of 1100)
iteration: 600 (of 1100)
iteration: 700 (of 1100)
iteration: 800 (of 1100)
iteration: 900 (of 1100)
iteration: 1000 (of 1100)
iteration: 1100 (of 1100)
time for loop: 11

Tree sizes, last iteration:
2 2 2 3 2 1 2 3 1 3 2 2 2 2 2 1 2 2 2 4 
3 2 1 2 1 2 3 2 1 2 2 2 2 1 1 2 2 2 2 3 
2 1 2 2 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 1 
1 2 2 2 2 2 2 2 2 2 3 2 2 3 2 3 2 2 2 2 
2 1 2 2 3 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 
2 2 2 2 2 3 2 2 1 3 2 3 1 1 1 1 2 2 1 2 
2 2 2 3 2 1 2 2 2 2 2 1 2 2 1 2 2 1 2 2 
2 2 2 1 1 1 2 2 1 2 2 3 2 2 2 2 2 2 2 2 
1 1 2 2 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 2 
2 2 2 1 2 3 1 2 1 2 1 2 2 2 1 2 3 2 2 3 
Variable Usage, last iteration (var:count):
(1: 0) (2: 0) (3: 0) (4: 0) (5: 0) 
(6: 1) (7: 1) (8: 0) (9: 2) (10: 1) 
(11: 1) (12: 3) (13: 2) (14: 7) (15: 0) 
(16: 0) (17: 3) (18: 3) (19: 2) (20: 1) 
(21: 2) (22: 2) (23: 3) (24: 3) (25: 2) 
(26: 4) (27: 2) (28: 1) (29: 1) (30: 3) 
(31: 1) (32: 6) (33: 3) (34: 3) (35: 1) 
(36: 1) (37: 1) (38: 2) (39: 1) (40: 2) 
(41: 4) (42: 3) (43: 0) (44: 1) (45: 1) 
(46: 1) (47: 1) (48: 2) (49: 0) (50: 0) 
(51: 3) (52: 0) (53: 0) (54: 0) (55: 0) 
(56: 0) (57: 0) (58: 0) (59: 0) (60: 0) 
(61: 0) (62: 0) (63: 0) (64: 0) (65: 0) 
(66: 0) (67: 0) (68: 0) (69: 0) (70: 0) 
(71: 0) (72: 0) (73: 0) (74: 0) (75: 0) 
(76: 0) (77: 0) (78: 0) (79: 0) (80: 0) 
(81: 0) (82: 0) (83: 0) (84: 3) (85: 0) 
(86: 0) (87: 0) (88: 0) (89: 0) (90: 0) 
(91: 0) (92: 0) (93: 0) (94: 0) (95: 0) 
(96: 0) (97: 0) (98: 0) (99: 0) (100: 0) 
(101: 0) (102: 0) (103: 0) (104: 0) (105: 0) 
(106: 0) (107: 0) (108: 0) (109: 0) (110: 0) 
(111: 0) (112: 0) (113: 0) (114: 0) (115: 0) 
(116: 0) (117: 0) (118: 0) (119: 0) (120: 0) 
(121: 0) (122: 0) (123: 0) (124: 0) (125: 0) 
(126: 0) (127: 0) (128: 0) (129: 2) (130: 0) 
(131: 0) (132: 0) (133: 0) (134: 0) (135: 0) 
(136: 0) (137: 0) (138: 0) (139: 0) (140: 0) 
(141: 0) (142: 0) (143: 0) (144: 0) (145: 0) 
(146: 0) (147: 0) (148: 0) (149: 0) (150: 0) 
(151: 0) (152: 0) (153: 0) (154: 0) (155: 0) 
(156: 0) (157: 0) (158: 0) (159: 0) (160: 0) 
(161: 0) (162: 0) (163: 0) (164: 0) (165: 0) 
(166: 0) (167: 0) (168: 0) (169: 0) (170: 0) 
(171: 0) (172: 0) (173: 0) (174: 0) (175: 0) 
(176: 0) (177: 0) (178: 0) (179: 0) (180: 0) 
(181: 0) (182: 0) (183: 0) (184: 0) (185: 0) 
(186: 0) (187: 0) (188: 0) (189: 0) (190: 0) 
(191: 0) (192: 0) (193: 0) (194: 0) (195: 0) 
(196: 0) (197: 0) (198: 0) (199: 0) (200: 0) 
(201: 0) (202: 0) (203: 0) (204: 0) (205: 0) 
(206: 0) (207: 0) (208: 0) (209: 0) (210: 0) 
(211: 0) (212: 0) (213: 0) (214: 0) (215: 0) 
(216: 0) (217: 0) (218: 2) (219: 0) (220: 0) 
(221: 0) (222: 0) (223: 0) (224: 0) (225: 0) 
(226: 0) (227: 0) (228: 0) (229: 0) (230: 0) 
(231: 0) (232: 0) (233: 0) (234: 0) (235: 4) 
(236: 2) (237: 0) (238: 0) (239: 0) (240: 0) 
(241: 0) (242: 0) (243: 0) (244: 0) (245: 0) 
(246: 0) (247: 3) (248: 3) (249: 2) (250: 0) 
(251: 1) (252: 3) (253: 1) (254: 4) (255: 2) 
(256: 7) (257: 2) (258: 5) (259: 1) (260: 4) 
(261: 0) (262: 3) (263: 7) (264: 1) (265: 3) 
(266: 6) (267: 2) (268: 4) (269: 1) (270: 4) 
(271: 2) (272: 4) (273: 1) (274: 3) 
DONE BART 11-2-2014

> p.score <- pnorm(colMeans(trees$yhat.train))
> trt <- dat$online==1
> ipw <- trt + (1-trt)/(1-p.score)
> 
> 
> outcomes <- c(names(dat[,which(grepl("^std_",colnames(dat)))]))
> 
> # Big Table 
> big.table <- array(NA,dim = c(34,5))
> rownames(big.table) <- c("Job Search","","Contrib. to Entrep.","","Garner Conts.","","Pers. Gain (% $100)","",
+                          "Group Gain (% $100)","","Political Hom.","","Religious Hom.","","Education Hom.",
+                          "","Class Hom.","","Pers. Crisis","","Pers. Success","","Prof. Crisis",
+                          "","Prof. Success","","Pref. Interaction","","Tie Strength","",
+                          "Least in Common","","Most in Common","")
> colnames(big.table) <- c("Clique","Weakest","Weak","Strong","Strongest")
> 
> full.forms <- list(NA)
> j = k = 1
> for(tie in c("clique","weakest","weak","strong","strongest")) {
+   forms.biv <- list(NA)
+   biv.outs <- list(NA)
+   outcomes.tie <- outcomes[which(grepl(tie,outcomes))]
+   
+   if(tie == "weak" | tie == "strong") {
+     outcomes.tie <- outcomes.tie[which(!(grepl("est",outcomes.tie)))]  
+   }
+   
+   for(i in 1:(length(outcomes.tie))) {
+     forms.biv[[i]] <- as.formula(paste(outcomes.tie[i],"~ online"))
+     full.forms[[j]] <- forms.biv[[i]]
+     biv.outs[[i]] <- lm(forms.biv[[i]],data=dat)
+     j = j+1
+   }
+   
+   coefs <- sapply(1:17,function(x) summary(biv.outs[[x]])$coefficients[2,1])
+   ses <- sapply(1:17,function(x) summary(biv.outs[[x]])$coefficients[2,2])
+   pvals <- sapply(1:17,function(x) summary(biv.outs[[x]])$coefficients[2,4])
+   stars <- ifelse(pvals < .01,"***",ifelse(pvals < .05,"**",ifelse(pvals < .1,"*","")))
+   
+   big.table[seq(1,34,by=2),k] <- paste(specify_decimal(coefs,3),stars,sep="")
+   big.table[seq(2,34,by=2),k] <- paste("(",specify_decimal(ses,3),")",sep="")
+   k = k+1
+ }
> 
> ords <- match(c("Political Hom.","Religious Hom.","Education Hom.","Class Hom.","Least in Common","Most in Common",
+                 "Contrib. to Entrep.","Garner Conts.","Pers. Gain (% $100)","Group Gain (% $100)",
+                 "Pers. Crisis","Pers. Success","Pref. Interaction","Tie Strength",
+                 "Job Search","Prof. Crisis","Prof. Success"),rownames(big.table))
> newords <- NA
> for(x in ords) {
+   newords <- c(newords,x,x+1)
+ }
> newords <- newords[-1]
> 
> big.table <- big.table[newords,]
> startup(big.table,keep.stat = c("N","rsq"),out = "./2_Tables/chars_regs.tex")

% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Fri, Mar 31, 2017 - 9:00:14 PM
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} cccccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & Clique & Weakest & Weak & Strong & Strongest \\ 
\hline \\[-1.8ex] 
Political Hom. &  0.026 &  0.086 & -0.174\textasteriskcentered  & -0.120 &  0.155 \\ 
 & (0.102) & (0.089) & (0.093) & (0.097) & (0.097) \\ 
Religious Hom. & -0.030 & -0.102 & -0.086 &  0.215\textasteriskcentered \textasteriskcentered  & -0.037 \\ 
 & (0.097) & (0.098) & (0.094) & (0.095) & (0.097) \\ 
Education Hom. & -0.073 & -0.004 &  0.026 &  0.084 & -0.042 \\ 
 & (0.096) & (0.096) & (0.097) & (0.097) & (0.096) \\ 
Class Hom. & -0.068 & -0.114 &  0.011 &  0.074 &  0.054 \\ 
 & (0.094) & (0.096) & (0.096) & (0.096) & (0.098) \\ 
Least in Common & -0.045 &  0.218\textasteriskcentered \textasteriskcentered  &  0.217\textasteriskcentered \textasteriskcentered  &  0.037 & -0.129 \\ 
 & (0.096) & (0.097) & (0.095) & (0.095) & (0.096) \\ 
Most in Common &  0.130 & -0.003 &  0.043 & -0.005 &  0.124 \\ 
 & (0.093) & (0.097) & (0.096) & (0.097) & (0.095) \\ 
Contrib. to Entrep. &  0.056 & -0.134 &  0.004 & -0.054 &  0.123 \\ 
 & (0.097) & (0.096) & (0.096) & (0.096) & (0.096) \\ 
Garner Conts. &  0.051 &  0.114 & -0.021 & -0.106 & -0.043 \\ 
 & (0.096) & (0.097) & (0.095) & (0.096) & (0.096) \\ 
Pers. Gain (\% \$100) &  0.074 & -0.037 & -0.004 & -0.075 &  0.028 \\ 
 & (0.097) & (0.096) & (0.094) & (0.096) & (0.094) \\ 
Group Gain (\% \$100) &  0.141 & -0.149 & -0.017 & -0.004 &  0.023 \\ 
 & (0.096) & (0.096) & (0.096) & (0.097) & (0.095) \\ 
Pers. Crisis &  0.114 &  0.028 &  0.120 & -0.150 & -0.037 \\ 
 & (0.096) & (0.095) & (0.096) & (0.097) & (0.093) \\ 
Pers. Success &  0.107 &  0.018 & -0.030 & -0.153 & -0.074 \\ 
 & (0.096) & (0.096) & (0.097) & (0.097) & (0.095) \\ 
Pref. Interaction & -0.001 &  0.396\textasteriskcentered \textasteriskcentered \textasteriskcentered  &  0.383\textasteriskcentered \textasteriskcentered \textasteriskcentered  &  0.446\textasteriskcentered \textasteriskcentered \textasteriskcentered  &  0.289\textasteriskcentered \textasteriskcentered \textasteriskcentered  \\ 
 & (0.099) & (0.095) & (0.093) & (0.094) & (0.093) \\ 
Tie Strength & -0.093 &  0.031 & -0.053 &  0.117 &  0.019 \\ 
 & (0.096) & (0.096) & (0.095) & (0.095) & (0.094) \\ 
Job Search &  0.107 & -0.048 &  0.108 & -0.146 & -0.021 \\ 
 & (0.096) & (0.096) & (0.096) & (0.097) & (0.096) \\ 
Prof. Crisis & -0.002 & -0.018 & -0.105 & -0.141 & -0.074 \\ 
 & (0.097) & (0.096) & (0.096) & (0.097) & (0.092) \\ 
Prof. Success &  0.083 & -0.099 &  0.001 & -0.157 & -0.155\textasteriskcentered  \\ 
 & (0.097) & (0.096) & (0.097) & (0.096) & (0.093) \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 
 [1] ""                                                                                                                
 [2] "% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu"       
 [3] "% Date and time: Fri, Mar 31, 2017 - 9:00:14 PM"                                                                 
 [4] "\\begin{table}[!htbp] \\centering "                                                                              
 [5] "  \\caption{} "                                                                                                  
 [6] "  \\label{} "                                                                                                    
 [7] "\\begin{tabular}{@{\\extracolsep{5pt}} cccccc} "                                                                 
 [8] "\\\\[-1.8ex]\\hline "                                                                                            
 [9] "\\hline \\\\[-1.8ex] "                                                                                           
[10] " & Clique & Weakest & Weak & Strong & Strongest \\\\ "                                                           
[11] "\\hline \\\\[-1.8ex] "                                                                                           
[12] "Political Hom. &  0.026 &  0.086 & -0.174${}^{*}$ & -0.120 &  0.155 \\\\ "                                       
[13] " & (0.102) & (0.089) & (0.093) & (0.097) & (0.097) \\\\ "                                                        
[14] "Religious Hom. & -0.030 & -0.102 & -0.086 &  0.215${}^{**}$  & -0.037 \\\\ "                                     
[15] " & (0.097) & (0.098) & (0.094) & (0.095) & (0.097) \\\\ "                                                        
[16] "Education Hom. & -0.073 & -0.004 &  0.026 &  0.084 & -0.042 \\\\ "                                               
[17] " & (0.096) & (0.096) & (0.097) & (0.097) & (0.096) \\\\ "                                                        
[18] "Class Hom. & -0.068 & -0.114 &  0.011 &  0.074 &  0.054 \\\\ "                                                   
[19] " & (0.094) & (0.096) & (0.096) & (0.096) & (0.098) \\\\ "                                                        
[20] "Least in Common & -0.045 &  0.218${}^{**}$  &  0.217${}^{**}$  &  0.037 & -0.129 \\\\ "                          
[21] " & (0.096) & (0.097) & (0.095) & (0.095) & (0.096) \\\\ "                                                        
[22] "Most in Common &  0.130 & -0.003 &  0.043 & -0.005 &  0.124 \\\\ "                                               
[23] " & (0.093) & (0.097) & (0.096) & (0.097) & (0.095) \\\\ "                                                        
[24] "Contrib. to Entrep. &  0.056 & -0.134 &  0.004 & -0.054 &  0.123 \\\\ "                                          
[25] " & (0.097) & (0.096) & (0.096) & (0.096) & (0.096) \\\\ "                                                        
[26] "Garner Conts. &  0.051 &  0.114 & -0.021 & -0.106 & -0.043 \\\\ "                                                
[27] " & (0.096) & (0.097) & (0.095) & (0.096) & (0.096) \\\\ "                                                        
[28] "Pers. Gain (\\% \\$100) &  0.074 & -0.037 & -0.004 & -0.075 &  0.028 \\\\ "                                      
[29] " & (0.097) & (0.096) & (0.094) & (0.096) & (0.094) \\\\ "                                                        
[30] "Group Gain (\\% \\$100) &  0.141 & -0.149 & -0.017 & -0.004 &  0.023 \\\\ "                                      
[31] " & (0.096) & (0.096) & (0.096) & (0.097) & (0.095) \\\\ "                                                        
[32] "Pers. Crisis &  0.114 &  0.028 &  0.120 & -0.150 & -0.037 \\\\ "                                                 
[33] " & (0.096) & (0.095) & (0.096) & (0.097) & (0.093) \\\\ "                                                        
[34] "Pers. Success &  0.107 &  0.018 & -0.030 & -0.153 & -0.074 \\\\ "                                                
[35] " & (0.096) & (0.096) & (0.097) & (0.097) & (0.095) \\\\ "                                                        
[36] "Pref. Interaction & -0.001 &  0.396${}^{***}$  &  0.383${}^{***}$  &  0.446${}^{***}$  &  0.289${}^{***}$  \\\\ "
[37] " & (0.099) & (0.095) & (0.093) & (0.094) & (0.093) \\\\ "                                                        
[38] "Tie Strength & -0.093 &  0.031 & -0.053 &  0.117 &  0.019 \\\\ "                                                 
[39] " & (0.096) & (0.096) & (0.095) & (0.095) & (0.094) \\\\ "                                                        
[40] "Job Search &  0.107 & -0.048 &  0.108 & -0.146 & -0.021 \\\\ "                                                   
[41] " & (0.096) & (0.096) & (0.096) & (0.097) & (0.096) \\\\ "                                                        
[42] "Prof. Crisis & -0.002 & -0.018 & -0.105 & -0.141 & -0.074 \\\\ "                                                 
[43] " & (0.097) & (0.096) & (0.096) & (0.097) & (0.092) \\\\ "                                                        
[44] "Prof. Success &  0.083 & -0.099 &  0.001 & -0.157 & -0.155${}^{*}$ \\\\ "                                        
[45] " & (0.097) & (0.096) & (0.097) & (0.096) & (0.093) \\\\ "                                                        
[46] "\\hline \\\\[-1.8ex] "                                                                                           
[47] "\\end{tabular} "                                                                                                 
[48] "\\end{table} "                                                                                                   
> 
> ######################################################################################
> # Free-step down resampling
> ######################################################################################
> plot.table <- array(NA,dim = c(34,20))
> pval.ctr <- pval.bart <- pval.cem <- pval.biv <- array(NA,dim = c(17,5))
> boot.ctr.t <- boot.cem.t <- boot.bart.t <- NA
> rownames(plot.table) <- c("Job Search","","Contrib. to Entrep.","","Garner Conts.","","Pers. Gain (% $100)","",
+                           "Group Gain (% $100)","","Political Hom.","","Religious Hom.","","Education Hom.",
+                           "","Class Hom.","","Pers. Crisis","","Pers. Success","","Prof. Crisis",
+                           "","Prof. Success","","Pref. Interaction","","Tie Strength","",
+                           "Least in Common","","Most in Common","")
> colnames(plot.table) <- sapply(c("Clique","Weakest","Weak","Strong","Strongest"),function(x) paste(x,c("Controls","CEM","BART","SUR"),sep=" "))
> k = l = 1
> for(tie in c("clique","weakest","weak","strong","strongest")) {
+   form.ctr <- outs.ctr <- form.biv <- outs.cem <- outs.bart <- outs.biv <- list(NA)
+   outcomes.tie <- outcomes[which(grepl(tie,outcomes))]
+   
+   if(tie == "weak" | tie == "strong") {
+     outcomes.tie <- outcomes.tie[which(!(grepl("est",outcomes.tie)))]  
+   }
+   
+   for(i in 1:(length(outcomes.tie))) {
+     form.ctr[[i]] <- as.formula(paste(outcomes.tie[i],"~ online+",paste(controls,collapse="+")))
+     form.biv[[i]] <- as.formula(paste(outcomes.tie[i],"~ online"))
+     
+     mod.biv <- summary(lm(form.biv[[i]],data=dat))
+     mod.ctr <- summary(lm(form.ctr[[i]],data=dat))
+     mod.cem <- att(cem.dat,form.biv[[i]],data=dat)
+     mod.bart <- summary(lm(form.biv[[i]],data=dat,weights=ipw))
+     
+     outs.biv[[i]] <- mod.biv$coefficients[2,1:2]
+     outs.ctr[[i]] <- mod.ctr$coefficients[2,1:2]
+     outs.cem[[i]] <- mod.cem$att.model[1:2,2]
+     outs.bart[[i]] <- mod.bart$coefficients[2,1:2]
+ 
+   }
+   Coefobs.biv <- unlist(outs.biv)[which(names(unlist(outs.biv)) == "Estimate")]
+   Coefobs.ctr <- unlist(outs.ctr)[which(names(unlist(outs.ctr)) == "Estimate")]
+   Coefobs.cem <- unlist(outs.cem)[which(names(unlist(outs.cem)) == "Estimate")]
+   Coefobs.bart <- unlist(outs.bart)[which(names(unlist(outs.bart)) == "Estimate")]
+   
+   Tobs.biv <- unlist(outs.biv)[which(names(unlist(outs.biv)) == "Estimate")]/unlist(outs.biv)[which(names(unlist(outs.biv)) == "Std. Error")]
+   Tobs.ctr <- unlist(outs.ctr)[which(names(unlist(outs.ctr)) == "Estimate")]/unlist(outs.ctr)[which(names(unlist(outs.ctr)) == "Std. Error")]
+   Tobs.cem <- unlist(outs.cem)[which(names(unlist(outs.cem)) == "Estimate")]/unlist(outs.cem)[which(names(unlist(outs.cem)) == "Std. Error")]
+   Tobs.bart <- unlist(outs.bart)[which(names(unlist(outs.bart)) == "Estimate")]/unlist(outs.bart)[which(names(unlist(outs.bart)) == "Std. Error")]
+   
+   Boot.ctr <- Boot.cem <- Boot.bart <- Boot.biv <- matrix(nrow = 100,ncol = length(outcomes.tie))
+   for(j in 1:100) {
+     SampID <- sample(1:nrow(dat),size = nrow(dat),replace = T)
+     bootdat <- dat[SampID,]
+     bootcem <- cem(treatment = "online",data=bootdat,drop=todrop)
+     resboot.biv <- resboot.ctr <- resboot.cem <- resboot.bart <- respval.ctr <- respval.cem <- respval.biv <- respval.bart <- matrix(nrow = length(outcomes.tie),ncol = 2)
+     for (i in 1:length(outcomes.tie)){
+       resboot.biv[i,] <- summary(lm(form.biv[[i]],data = bootdat))$coefficients[2,1:2]
+       resboot.ctr[i,] <- summary(lm(form.ctr[[i]],data = bootdat))$coefficients[2,1:2]
+       resboot.cem[i,] <- att(bootcem,form.biv[[i]],data=bootdat)[[1]][1:2,2]
+       resboot.bart[i,] <- summary(lm(form.biv[[i]],data = bootdat,weights = ipw[SampID]))$coefficients[2,1:2]
+     }
+     if(length(resboot.biv[,1]) == length(Coefobs.biv)) {
+       Boot.biv[j,] <- (resboot.biv[,1] - Coefobs.biv)/resboot.biv[,2]
+     }
+     if(length(resboot.ctr[,1]) == length(Coefobs.ctr)) {
+       Boot.ctr[j,] <- (resboot.ctr[,1] - Coefobs.ctr)/resboot.ctr[,2]
+     }
+     if(length(resboot.cem[,1]) == length(Coefobs.cem)) {
+       Boot.cem[j,] <- (resboot.cem[,1] - Coefobs.cem)/resboot.cem[,2]
+     }
+     if(length(resboot.bart[,1]) == length(Coefobs.bart)) {
+       Boot.bart[j,] <- (resboot.bart[,1] - Coefobs.bart)/resboot.bart[,2]
+     }
+     cat(paste(j,"\n"))
+   }
+   
+   Qmat.biv <- t(apply(Boot.biv,1,cummax))
+   Qmat.ctr <- t(apply(Boot.ctr,1,cummax))
+   Qmat.cem <- t(apply(Boot.cem,1,cummax))
+   Qmat.bart <- t(apply(Boot.bart,1,cummax))
+ 
+   pval.biv[,l] <- apply(t(matrix(rep(Tobs.biv,100),17)) <= Qmat.biv,2,mean)
+   pval.ctr[,l] <- apply(t(matrix(rep(Tobs.ctr,100),17)) <= Qmat.ctr,2,mean)
+   pval.cem[,l] <- apply(t(matrix(rep(Tobs.cem,100),17)) <= Qmat.cem,2,mean)
+   pval.bart[,l] <- apply(t(matrix(rep(Tobs.bart,100),17)) <= Qmat.bart,2,mean)
+   
+   cj.tmp.ctr <- cj.tmp.cem <- cj.tmp.bart <- NA
+   ref <- seq(2.5,3.5,.05)
+   z = 1
+   for(cj in ref) {
+     cj.tmp.ctr[z] <- mean(apply(abs(Boot.ctr)>cj,1,sum)>= 1,na.rm=T)
+     cj.tmp.cem[z] <- mean(apply(abs(Boot.cem)>cj,1,sum)>= 1,na.rm=T)
+     cj.tmp.bart[z] <- mean(apply(abs(Boot.bart)>cj,1,sum)>= 1,na.rm=T)
+     z = z+1
+   }
+   
+   boot.ctr.t[l] <- ref[which(abs(0.05 - cj.tmp.ctr) == min(abs(0.05 - cj.tmp.ctr)))][1]
+   boot.cem.t[l] <- ref[which(abs(0.05 - cj.tmp.cem) == min(abs(0.05 - cj.tmp.cem)))][1]
+   boot.bart.t[l] <- ref[which(abs(0.05 - cj.tmp.bart) == min(abs(0.05 - cj.tmp.bart)))][1]
+   
+   outs.sur <- systemfit(form.biv,data=dat,method = "SUR")
+   
+   plot.table[seq(1,34,by=2),k] <- unlist(outs.ctr)[seq(1,34,by=2)]
+   plot.table[seq(2,34,by=2),k] <- unlist(outs.ctr)[seq(2,34,by=2)]
+   k = k+1
+   plot.table[seq(1,34,by=2),k] <- unlist(outs.cem)[seq(1,34,by=2)]
+   plot.table[seq(2,34,by=2),k] <- unlist(outs.cem)[seq(2,34,by=2)]
+   k = k+1
+   plot.table[seq(1,34,by=2),k] <- unlist(outs.bart)[seq(1,34,by=2)]
+   plot.table[seq(2,34,by=2),k] <- unlist(outs.bart)[seq(2,34,by=2)]
+   k = k+1
+   plot.table[seq(1,34,by=2),k] <- summary(outs.sur)$coefficients[seq(2,34,by=2),1]
+   plot.table[seq(2,34,by=2),k] <- summary(outs.sur)$coefficients[seq(2,34,by=2),2]
+   k = k+1
+   l = l+1
+ }
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
> 
> ctr.n <- summary(lm(form.ctr[[i]],data=dat))$df[2]
> cem.n <- sum(att(cem.dat,form.biv[[i]],data=dat)[[2]][2,])
> bart.n <- summary(lm(form.biv[[i]],data=dat,weights = ipw))$df[2]
> 
> ctr.stat <- qt((1-.025),df = ctr.n)
> ctr.bonf <- qt(1-(.025/length(outcomes.tie)),df = ctr.n)
> cem.stat <- qt((1-.025),df = cem.n)
> cem.bonf <- qt((1-(.025/length(outcomes.tie))),df = cem.n)
> bart.stat <- qt((1-.025),df = bart.n)
> bart.bonf <- qt((1-(.025/length(outcomes.tie))),df = bart.n)
> 
> ######################################################################################
> # SI_chars_regs.pdf: Supporting Information Figure 1
> ######################################################################################
> oldnames <- rownames(plot.table)
> ords <- match(c("Political Hom.","Religious Hom.","Education Hom.","Class Hom.","Least in Common","Most in Common",
+                 "Contrib. to Entrep.","Garner Conts.","Pers. Gain (% $100)","Group Gain (% $100)",
+                 "Pers. Crisis","Pers. Success","Pref. Interaction","Tie Strength",
+                 "Job Search","Prof. Crisis","Prof. Success"),rownames(plot.table))
> newords <- NA
> for(x in ords) {
+   newords <- c(newords,x,x+1)
+ }
> newords <- newords[-1]
> plot.table <- plot.table[newords,]
> pdf("./1_Figures/SI_chars_regs.pdf")
>   nf <- layout(matrix(c(1,2,3,4,5,6,7,7,7,7,7,7),2,6,byrow=T),widths=c(2,1.4,1.4,1.4,1.4,1.4),heights=c(7,.5))
>   par(mar=c(1,.5,3,.5))
>   plot(rep(0,17),1:17,type='n',xlab="",ylab="",xaxt='n',yaxt='n',bty='n')
>   mtext(text = rev(rownames(plot.table[seq(1,34,by=2),])),side = 2,at = 1:17,las=2,cex=.8,line = -10)
>   j <- 1
>   for(tie in c("clique","weakest","weak","strong","strongest")) {
+     mins <- min(plot.table[seq(1,34,by=2),j:(j+3)] - 3.1*plot.table[seq(2,34,by=2),j:(j+3)])
+     maxs <- max(plot.table[seq(1,34,by=2),j:(j+3)] + 3.1*plot.table[seq(2,34,by=2),j:(j+3)])
+     
+     plot(plot.table[seq(1,34,by=2),1],1:17,xlim=c(mins,maxs),xaxt='n',yaxt='n',xlab="",ylab="",type='n',bty='n',main=capitalize(tie),cex.main = 1.3)
+     box(col=rgb(0,0,0,.3))
+     #axis(side = 1,at=seq(round(mins),round(maxs),length.out=5),labels=seq(round(mins),round(maxs),length.out=5),cex.axis=.8,col=rgb(0,0,0,.7))
+     yadj <- .3
+     k = 1
+     for(i in j:(j+3)) {
+       tstats <- abs(rev(plot.table[seq(1,34,by=2),i])/rev(plot.table[seq(2,34,by=2),i]))
+       pt.cols <- ifelse(tstats > ctr.bonf,rgb(0,0,0,.5),
+                         ifelse(tstats > ctr.stat,rgb(0,0,0,.3),rgb(0,0,0,.05)))
+       rect(rev(plot.table[seq(1,34,by=2),i]) - ctr.bonf*rev(plot.table[seq(2,34,by=2),i]),(1:17)+yadj-.05,
+                rev(plot.table[seq(1,34,by=2),i]) + ctr.bonf*rev(plot.table[seq(2,34,by=2),i]),(1:17)+yadj+.05,
+            col=NA,border=pt.cols)
+       rect(rev(plot.table[seq(1,34,by=2),i]) - ctr.stat*rev(plot.table[seq(2,34,by=2),i]),(1:17)+yadj-.05,
+            rev(plot.table[seq(1,34,by=2),i]) + ctr.stat*rev(plot.table[seq(2,34,by=2),i]),(1:17)+yadj+.05,
+            col=pt.cols,border = NA)
+       points(rev(plot.table[seq(1,34,by=2),i]),(1:17)+yadj,pch=k,cex=.8,col = pt.cols)
+       yadj <- yadj - .15
+       k = k+1
+     }
+     abline(v = 0,lty=3)
+     j <- j+4
+   }
>   
>   #text(max(plot.table[1,17:20] + ctr.bonf*plot.table[2,17:20]*1.1),
>   #     c(17.4,17.2,17,16.8),labels = c("Controls","CEM","BART","SUR"),adj = 0,cex=.9)
>   par(mar=c(0,6,0,0))
>   plot(0,type='n',xlab="",ylab="",xaxt='n',yaxt='n',bty='n')
>   leg2("top",legend=c("Controls","CEM","BART","SUR","MC Significant","95% Significant"),
+          pch=c(1:4,NA,NA),fill=c(NA,NA,NA,NA,"white","grey60"),fill.lty = c(0,0,0,0,1,1),
+          col=c(rep("black",5),"grey50"),ncol=3,bty='n',cex = 1.2)
> dev.off()
null device 
          1 
> 
> ######################################################################################
> # chars_adjpvals.pdf: Figure 4
> ######################################################################################
> ords <- rev(order(apply(cbind(pval.biv[,2:5],pval.cem[,2:5],pval.ctr[,2:5],pval.bart[,2:5]),1,min)))
> sizes <- ifelse(pval.bart[,1] < .05,1.2,1)
> 
> pdf("./1_Figures/chars_adjpvals.pdf")
> par(mar=c(5,9,3,1))
> plot(1-jitter(pval.bart[,1][ords]),1:17,xlim=c(0,1),pch=19,col=rgb(0,0,0,.2),yaxt='n',ylab="",xlab="Confidence Level",bty='n',type = 'n',
+      main="Adjusted Level of Confidence")
> mtext(text = oldnames[seq(1,34,by=2)][ords],side = 2,at = 1:17,las=2,cex=1,line = 1)
> for(i in 2:5) {
+   pvs <- jitter(pval.bart[,i],amount = .01) #ifelse(pval.bart[,i] > .5,.5,jitter(pval.bart[,i]))
+   sizes <- ifelse(pvs < .05,1.3,.4)
+   cols <- ifelse(pvs > .05,rgb(0,0,0,.1),rgb(0,0,0,.5))
+   pchs <- ifelse(pvs < .05,21,19)
+   points(1-pvs[ords],1:17,pch=pchs[ords],col="black",cex = sizes[ords])
+ }
> for(i in 2:5) {
+   pvs <- jitter(pval.ctr[,i],amount = .01) #ifelse(pval.ctr[,i] > .5,.5,jitter(pval.ctr[,i]))
+   cols <- ifelse(pvs > .05,rgb(0,0,0,.1),rgb(0,0,0,.5))
+   sizes <- ifelse(pvs < .05,1.3,.4)
+   pchs <- ifelse(pvs < .05,21,19)
+   points(1-pvs[ords],1:17,pch=pchs[ords],col="black",cex = sizes[ords])
+ }
> for(i in 2:5) {
+   pvs <- jitter(pval.biv[,i],amount = .01) #ifelse(pval.ctr[,i] > .5,.5,jitter(pval.ctr[,i]))
+   sizes <- ifelse(pvs < .05,1.3,.4)
+   cols <- ifelse(pvs > .05,rgb(0,0,0,.1),rgb(0,0,0,.5))
+   pchs <- ifelse(pvs < .05,21,19)
+   points(1-pvs[ords],1:17,pch=pchs[ords],col="black",cex = sizes[ords])
+ }
> for(i in 2:5) {
+   pvs <- jitter(pval.cem[,i],amount = .01) #ifelse(pval.ctr[,i] > .5,.5,jitter(pval.ctr[,i]))
+   cols <- ifelse(pvs > .05,rgb(0,0,0,.1),rgb(0,0,0,.5))
+   sizes <- ifelse(pvs < .05,1.3,.4)
+   pchs <- ifelse(pvs < .05,21,19)
+   points(1-pvs[ords],1:17,pch=pchs[ords],col="black",cex = sizes[ords])
+ }
> 
> abline(v = 0.95,lty=2)
> abline(h = 1:17,lty=3,col=rgb(0,0,0,.1))
> legend("bottomright",legend=c("Sig. @ 95%","Insignificant"),pch=c(21,19),pt.cex = c(1.5,.6),col="black",bty='o',bg = "white")
> dev.off()
null device 
          1 
> 
> ############################################################################
> # chars_diffs.pdf: Figure 5
> ############################################################################
> dat <- read.dta("./characteristics/chars_diffs.dta")
> coefs <- dat[,1]
> ses <- dat[,2]
> y.axis <- c(1:17)
> min <- -.65
> max <- .65
> dat$names <- c("Least in Common","Garner Conts.","Pers. Success","Education Hom.","Prof. Success","Pref. Interaction","Tie Strength","Pers. Crisis","Personal Gain (% $100)","Prof. Crisis","Job Search","Religious Hom.","Most in Common","Class Hom.","Political Hom.","Group Gain (% $100)","Contrib. to Entrep.")
> var.names <- dat$names
> adjust <- 0.05
> 
> pdf("./1_Figures/chars_diffs.pdf",width = 6,height=5)
> par(mar=c(5,10,3,1))
> plot(coefs, y.axis, type = "p", axes = F, xlab = "Online Coefficient", ylab = "", pch = 19, cex = .8, 
+      xlim=c(min,max),ylim = c(.5,17.5), main = "Diff. between Weakest / Strongest")
> axis(1, at = seq(min,max,by=.1),labels = seq(min,max,by=.1),tick = T,cex.axis = .8, mgp = c(2,.7,0))
> axis(2, at = y.axis, label = var.names, las = 1, tick = FALSE, cex.axis =.8)#,pos=-.45)
> rect(coefs-qnorm(1-0.025/length(y.axis))*ses, y.axis-.25, coefs+qnorm(1-0.025/length(y.axis))*ses, y.axis+.25,
+      col=NA,border=rgb(0,0,0,.3))
> rect(coefs-qnorm(.975)*ses, y.axis-.25, coefs+qnorm(.975)*ses, y.axis+.25, col=rgb(0,0,0,.3),border = NA)
> abline(v=0, lty = 2) 
> points(coefs, y.axis,pch=21,cex=.8, bg="white")
> 
> leg2("bottomright",legend=c("MC CI","95% CI"),
+      fill=c("white","grey70"),
+      border="grey60",bty='n',cex=.8,bg="white")
> dev.off()
null device 
          1 
> 
> ############################################################################
> # structure-diff-elicited.pdf: Figure 6
> ############################################################################
> ttest.coefs <- function(beta1,beta2,se1,se2) {
+   t.stat <- (beta1-beta2)/(sqrt(se1^2 + se2^2))
+   diff <- abs(beta1 - beta2)
+   pval <- 2*pt(-abs(t.stat),df = 450)
+   star <- paste("(",sprintf("%.2f",round(pval,2)),ifelse(pval < 0.05,"*)",")"),sep="")
+   return(list(star = star,pval = pval,diff = diff))
+ }
> 
> scaffold <- matrix(rbind(c(0,2,0,3,1,0),c(2,0,2,1,3,1),c(0,2,0,0,1,3),c(3,1,0,0,2,0),c(1,3,1,2,0,2),c(0,1,3,0,2,0)),nrow=6,ncol=6)
> 
> dat <- read.dta("./tools/data_prepped.dta")
> 
> # Seat Assignment Differences
> pdf("./1_Figures/structure-diff-elicited.pdf")
> nf <- layout(matrix(1:24,6,4,byrow=T),widths=c(1.5,3,3,3))
> #layout.show(nf)
> for(tie in c("clique","weakest","weak","strong","strongest","you")) {
+   mains <- c("","","")
+   if(tie == "clique") {
+     mains <- c("Online","Offline","Difference")
+   }
+   tie.on <- tie.off <- pvals <- diffs <- NA
+   for(i in 0:5) {
+     on <- dat %>% filter(online == 1)
+     off <- dat %>% filter(online == 0)
+     tie.on[i+1] <- mean(on[,paste("seat_mst_",tie,sep="")] == i,na.rm=T)
+     tie.off[i+1] <- mean(off[,paste("seat_mst_",tie,sep="")] == i,na.rm=T)
+     pvals[i+1] <- t.test(on[,paste("seat_mst_",tie,sep="")] == i,off[,paste("seat_mst_",tie,sep="")] == i)$p.value
+     diffs[i+1] <- abs(tie.on[i+1] - tie.off[i+1])
+   }
+   par(mar=c(0,0,0,0))
+   plot.new()
+   text(0,.5,labels=capitalize(tie),pos = 4,cex = 1.5)
+   
+   par(mar=c(1,1,3,1))
+   nw.graph.diff <- graph.adjacency(scaffold,weighted = T)
+   V(nw.graph.diff)$color <- "black"
+   norm <- (tie.on - min(tie.on))/(max(tie.on) - min(tie.on))+1
+   V(nw.graph.diff)$size <- norm*20
+   
+   E(nw.graph.diff)$lty <- 1
+   E(nw.graph.diff)$lty[which(E(nw.graph.diff)$weight == 1)] <- 3
+   
+   plot.igraph(nw.graph.diff,
+               layout = layout.grid,
+               edge.width = (E(nw.graph.diff)$weight^2)/3,
+               edge.arrow.size = 0,
+               edge.color = "black",
+               vertex.frame.color = "black",
+               vertex.label.dist = 2,
+               vertex.label.degree = c(rep(pi/2,3),rep(-pi/2,3)),
+               vertex.label = round(tie.on,2),
+               vertex.label.color = "black",
+               main = mains[1])
+   
+   
+   nw.graph.diff <- graph.adjacency(scaffold,weighted = T)
+   V(nw.graph.diff)$color <- "black"
+   norm <- (tie.off - min(tie.off))/(max(tie.off) - min(tie.off))+1
+   V(nw.graph.diff)$size <- norm*20
+   
+   E(nw.graph.diff)$lty <- 1
+   E(nw.graph.diff)$lty[which(E(nw.graph.diff)$weight == 1)] <- 3
+   
+   plot.igraph(nw.graph.diff,
+               layout = layout.grid,
+               edge.width = (E(nw.graph.diff)$weight^2)/3,
+               edge.arrow.size = 0,
+               edge.color = "black",
+               vertex.frame.color = "black",
+               vertex.label.dist = 2,
+               vertex.label.degree = c(rep(pi/2,3),rep(-pi/2,3)),
+               vertex.label = round(tie.off,2),
+               vertex.label.color = "black",
+               main = mains[2])
+   
+   nw.graph.diff <- graph.adjacency(scaffold,weighted = T)
+   V(nw.graph.diff)$color <- ifelse(pvals < 0.00028,"black",ifelse(pvals < 0.05,rgb(0,0,0,.2),"white"))
+   norm <- (diffs - min(diffs))/(max(diffs) - min(diffs))+1
+   V(nw.graph.diff)$size <- norm*20
+   
+   E(nw.graph.diff)$lty <- 1
+   E(nw.graph.diff)$lty[which(E(nw.graph.diff)$weight == 1)] <- 3
+   
+   plot.igraph(nw.graph.diff,
+               #margin=c(0,-.5,0,-.5),
+               layout = layout.grid,
+               edge.width = (E(nw.graph.diff)$weight^2)/3,
+               edge.arrow.size = 0,
+               edge.color = "black",
+               vertex.frame.color = "black",
+               vertex.label.dist = 2,
+               vertex.label.degree = c(rep(pi/2,3),rep(-pi/2,3)),
+               vertex.label = paste(sprintf("%.2f",round(diffs,2)),ifelse(pvals < 0.00028,"**",ifelse(pvals < 0.05,"*","")),sep=""),
+               vertex.label.color = "black",
+               main = mains[3])
+ }
> dev.off()
null device 
          1 
> 
> extract.dimension.avgs <- function(dimension,dat) {
+   dim.res <- data.frame(pos0=as.numeric(),pos1=as.numeric(),pos2=as.numeric(),pos3=as.numeric(),pos4=as.numeric(),pos5=as.numeric(),online = as.numeric())
+   for(i in 1:nrow(dat)) {
+     tmp <- dat %>% 
+       select(contains("seat_mst")) %>% 
+       select(-contains("synth"),-contains("connected")) %>% 
+       slice(i)
+     
+     dim <- dat[i,grepl(dimension,colnames(dat))]
+     
+     names(dim) <- substr(names(dim),nchar(dimension)+2,100)
+     dim <- dim[,which(colnames(dim) %in% c("weakest","weak","strong","strongest","clique"))]
+     dim$you <- NA
+     
+     ties <- substr(names(tmp)[order(tmp)],10,100)
+     tmp <- tmp[order(tmp)]
+     names(tmp) <- ties
+     
+     colords <- match(names(tmp),names(dim))
+     dim.res[i,] <- cbind(dim[1,colords],dat[i,"online"])
+   }
+   ttests <- sapply(1:6, function(y) t.test(dim.res %>% filter(online == 1) %>% select(y),dim.res %>% filter(online == 0) %>% select(y)))
+   diffs <- sapply(1:6, function(y) abs(ttests[,y]$estimate[1] - ttests[,y]$estimate[2]))
+   pvals <- sapply(1:6, function(y) ttests[,y]$p.value)
+   return(list(dim.res,diffs,pvals))
+ }
> 
> 
> ############################################################################
> # structure-diff-allchars.pdf: Figure 7
> ############################################################################
> lookup <- cbind(c("jobsearch","donate","interaction","garner","contribute","personalgain","grpgain",
+                   "prof_cris_synth","prof_succ_synth","pers_cris_synth","pers_succ_synth",
+                   "homophily_political","homophily_religious","homophily_education","homophily_life_skills","tie"),
+                 c("Job Search","Donate (% $100)","Pref. Interaction","Garner Conts.","Contrib. to Entrep.","Personal Gain (% $100)","Group Gain (% $100)",
+                   "Prof. Crisis","Prof. Success","Pers. Crisis","Pers. Success",
+                   "Political Hom.","Religious Hom.","Education Hom.","Class Hom.","Tie Strength"))
> 
> 
> pdf("./1_Figures/structure-diff-allchars.pdf")
>   par(mfrow=c(4,4),mar=c(2,1,3,1))
>   for(d in c("homophily_political","homophily_religious","homophily_education","homophily_life_skills",
+              "contribute","garner","personalgain","grpgain",
+              "pers_cris_synth","pers_succ_synth","interaction","tie",
+              "jobsearch","prof_cris_synth","prof_succ_synth")) {
+     result <- extract.dimension.avgs(d,dat)
+     nw.graph.diff <- graph.adjacency(scaffold,weighted = T)
+     V(nw.graph.diff)$color <- ifelse(result[[3]] < 0.00028,"black",ifelse(result[[3]] < 0.05,rgb(0,0,0,.2),"white"))
+     norm <- (result[[2]] - min(result[[2]]))/(max(result[[2]]) - min(result[[2]]))+1
+     V(nw.graph.diff)$size <- norm*10
+     
+     E(nw.graph.diff)$lty <- 1
+     E(nw.graph.diff)$lty[which(E(nw.graph.diff)$weight == 1)] <- 3
+     
+     plot.igraph(nw.graph.diff,
+                 layout = layout.grid,
+                 edge.width = (E(nw.graph.diff)$weight^2)/3,
+                 edge.arrow.size = 0,
+                 edge.color = "black",
+                 vertex.frame.color = "black",
+                 vertex.label.dist = 1.7,
+                 vertex.label.degree = c(rep(pi/2,3),rep(-pi/2,3)),
+                 vertex.label = paste(sprintf("%.2f",round(result[[2]],2)),ifelse(result[[3]] < 0.00028,"**",
+                                                                                  ifelse(result[[3]] < 0.05,"*","")),sep=""),
+                 vertex.label.color = "black",
+                 main = lookup[which(lookup[,1] == d),2])
+   }
>   plot.new()
>   legend("top",legend=c("*  Sig @ 95%","**  Sig @ MC"),fill=c(rgb(0,0,0,.2),"black"),border=c(NA,NA),bty='n')
> dev.off()
null device 
          1 
> 
> proc.time()
   user  system elapsed 
 153.89    0.93  155.39 
